/*
    backend for TimeTagger, an OpalKelly based single photon counting library
    Copyright (C) 2011  Markus Wick <wickmarkus@web.de>

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License along
    with this program; if not, write to the Free Software Foundation, Inc.,
    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#ifndef BACKEND_HISTOGRAM_H_
#define BACKEND_HISTOGRAM_H_

#include <map>
#include "TimeTagger.h"

class Histogram : public _Iterator {
public:
	Histogram(int chan, int chan2 = -1, long long binwidth=1000);
	virtual ~Histogram();

	virtual const char *getClassName();
	virtual const char * getScpiCommand();
	virtual std::string getScpiParameters();
	virtual void getMeta(long long **ARGOUTVIEWM_ARRAY2, int *DIM1);

	virtual void start();
	void getData(long long **ARGOUTVIEWM_ARRAY2, int *DIM1, int *DIM2);
	virtual void clear();

protected:
	virtual void next(Tag* list, int count, long long time);

private:
	std::map<long long,long long> data;
	int channel;
	int channel2;
	long long binwidth;
	long long last;
};

class Distribution : public _Iterator {
public:
	Distribution(int chan, int _divisor);
    virtual ~Distribution();

    virtual const char *getClassName();
	virtual const char * getScpiCommand();
	virtual std::string getScpiParameters();
	virtual void getMeta(long long **ARGOUTVIEWM_ARRAY2, int *DIM1);

	void getData(long long **ARGOUTVIEWM_ARRAY1, int *DIM1);
	virtual void clear();

protected:
	virtual void next (Tag *list, int count, long long time);

private:
	int channel;
	int divisor;
	long long *counts;
};

#endif /* HISTOGRAM_H_ */
